<template>
  <div class="discovery">
    <div class="banner-warmp">
      <el-carousel :interval="4000" type="card" class="banner-carousel">
        <el-carousel-item v-for="item of bannerList" :key="item.scm">
          <img :src="item.imageUrl" class="banner-img" alt />
        </el-carousel-item>
      </el-carousel>
    </div>

    <div class="playlist">
      <div class="item-title">最新歌单</div>
      <ul class="inner-list">
        <li
          class="playlist-item"
          v-for="item of newSongsList"
          :key="item.id"
          @click="handlePlayList(item)"
        >
          <div class="playlist-box">
            <img
              :src="$utils.getImgUrl(item.picUrl, 300, 300)"
              alt
              class="palylist-img"
            />
            <div class="playlist-item-top">{{ item.copywriter }}</div>
            <div class="playlist-btn">
              <i class="play-icon iconfont icon-component icon-play"></i>
            </div>
            <div class="playlist-bottom">{{ item.name }}</div>
          </div>
        </li>
      </ul>
    </div>

    <div class="songs">
      <div class="item-title">推荐音乐</div>
      <div class="songsList">
        <ul class="songsList-warmp">
          <li
            class="songsList-item"
            v-for="(item, index) of sigerList"
            :key="item.id"
            @click="hangleplaysongs(item)"
          >
            <span class="songsList-number">{{
              index + 1 >= 10 ? index + 1 : "0" + (index + 1)
            }}</span>

            <div class="songsList-img-box">
              <img
                class="songsList-img"
                :src="$utils.getImgUrl(item.picUrl, 200, 200)"
                alt
              />
              <div class="songsList-btn-backgroud">
                <i class="play-icon iconfont icon-component icon-play"></i>
              </div>
            </div>
            <div class="songsList-text">
              <div class="songsList-songs">{{ item.name }}</div>
              <div class="songList-sigers">{{ item.artistName }}</div>
            </div>
          </li>
        </ul>
      </div>
    </div>

    <div class="mvs">
      <div class="item-title">最新mv</div>

      <div class="mvs-Content-wramp">
        <ul class="mvs-Content-list">
          <li
            class="mvs-Content-item"
            v-for="item of MvsList"
            :key="item.id"
            @click="handleplaymv(item)"
          >
            <div class="mvs-Content-box">
              <img
                :src="$utils.getImgUrl(item.picUrl, 170, 100)"
                alt
                class="mvs-Content-img"
              />
              <div class="mvs-Content-top-img-title">
                <i class="iconfont icon-component icon-play"></i>
                {{ item.playCount }}
              </div>

              <div class="mvs-Content-hover-background">
                <i class="play-icon iconfont icon-component icon-play"></i>
              </div>
              <div class="mvs-Content-foot-songs">{{ item.name }}</div>
              <div class="mvs-Content-foot-sigers">{{ item.artistName }}</div>
            </div>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
import {
  fetchPerson,
  fetchBanner,
  fetchDiscoverSGer,
  fetchDiscoverMv,
} from "../api";
import { mapState, mapMutations } from "vuex";

export default {
  data() {
    return {
      bannerList: [],
      newSongsList: [],
      sigerList: [],
      MvsList: [],
      itemId: [],
    };
  },
  computed: {
    ...mapState(["currentSong", "isPlay"]),
  },
  mounted() {
    this.init();
  },
  methods: {
    ...mapMutations(["setCurrentSong", "setplaystatus"]),
    init() {
      this.getbanner();
      this.getPerson();
      this.getsigerlist();
      this.getMvlist();
    },

    getbanner() {
      fetchBanner({ type: 0 }).then((res) => {
        this.bannerList = res.banners;
      });
    },

    getPerson() {
      fetchPerson({ limit: 10 })
        .then((res) => {
          this.newSongsList = res.result;
        })
        .catch((err) => {
          console.error(err);
        });
    },
    getsigerlist() {
      fetchDiscoverSGer().then((res) => {
        this.sigerList = res.result;
        //console.log(res.result);
      });
    },
    getMvlist() {
      fetchDiscoverMv().then((res) => {
        this.MvsList = res.result;
        //console.log(res.result);
      });
    },
    handlePlayList(itemId) {
      this.$router.push({
        path: "/PlaylistDetail",
        query: {
          Arrid: itemId.id,
        },
      });
    },
    hangleplaysongs(item) {
      this.setCurrentSong(item);
      this.setplaystatus(true);
    },
    handleplaymv(item) {
      this.$router.push({
        path: "/playmv",
        query: {
          Arrid: item.id,
          ArtistId: item.artistId,
        },
      });
    },
  },
};
</script>

<style lang='less' scoped>
.discovery {
  padding: 0 40px;

  .item-title {
    color: #000;
    padding: 10px 0;
    font-size: 20px;
  }
  .banner-warmp {
    padding: 30px 0;
    .banner-carousel {
      /deep/.el-carousel__container {
        height: 210px;
      }

      .banner-img {
        width: 120%;
        height: 100%;
        border-radius: 4px;
        min-width: 240px;
      }
    }
  }
  .playlist {
    .inner-list {
      display: flex;
      flex-wrap: wrap;
    }
    .playlist-item {
      width: 20%;
      min-width: 120px;
      padding: 0 16px 18px 0;
      flex-shrink: 1;
    }

    .playlist-box {
      position: relative;

      border-radius: 6px;
      overflow: hidden;
      &:hover {
        .playlist-item-top {
          transform: translateY(0);
        }
        .playlist-btn {
          transform: translateX(0);
        }
      }
    }

    .palylist-img {
      width: 100%;

      vertical-align: top;
      border-radius: 6px;
    }
    .playlist-item-top {
      position: absolute;

      width: 100%;
      top: 0;
      left: 0;
      background-color: rgba(0, 0, 0, 0.3);
      font-size: 12px;
      line-height: 18px;
      color: #fff;
      padding: 4px 8px;
      transform: translateY(-120%);
      transition: all 0.3s;
    }
    .playlist-bottom {
      width: 100%;
      //设置一个宽度   不然三件套不起作用
      font-size: 12px;
      color: #666;
      padding-top: 7px;

      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      //拧出文字变点点的三件套
    }
    .playlist-btn {
      position: absolute;
      bottom: 29px;
      right: 10px;
      width: 36px;
      height: 36px;
      background-color: rgba(255, 255, 255, 0.8);
      color: red;
      text-align: center;
      line-height: 39px;
      border-radius: 50%;
      transform: translateX(120%);

      i {
        font-size: 24px;
        margin-left: 2px;
      }
    }
  }
  //首页第二个的歌单列表
  .songs {
    padding: 20px 0px;
    .item-title {
      width: 100%;
    }
    .songsList {
      width: 100%;
    }
    .songsList-warmp {
      position: relative;
      width: 100%;
      display: flex;
      flex-wrap: wrap;
      padding-top: 8px;
      overflow: hidden;
    }
    .songsList-item {
      min-width: 300px;

      position: relative;
      width: 50%;
      flex-shrink: 1;
      &:hover {
        background-color: #e6e5e6;
      }
    }
    .songsList-number {
      position: absolute;
      left: 10px;
      line-height: 80px;
      font-size: 14px;
      text-align: center;
      color: #4a4a4a;
    }
    .songsList-img-box {
      .songsList-img {
        margin: 8px 54px;
        height: 60px;
        width: 60px;
      }
      .songsList-btn-backgroud {
        position: absolute;
        top: 24px;
        left: 73px;
        width: 25px;
        height: 25px;
        background-color: rgba(255, 255, 255, 0.7);
        line-height: 29px;
        text-align: center;
        color: red;
        border-radius: 50%;

        // opacity: 0;
        // transition: all 0.3s;

        i {
          font-size: 16px;
          margin-left: 1px;
        }
      }
    }
    .songsList-text {
      position: absolute;
      top: 12px;
      left: 140px;
      .songsList-songs,
      .songList-sigers {
        color: #4a4a4a;
        font-size: 13px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
      .songsList-songs {
        padding-bottom: 10px;
      }
      .songList-sigers {
        padding-top: 10px;
      }
    }
  }

  //首页第三个的mv列表
  .mvs {
    padding: 20px 0px;
    .item-title {
      width: 100%;
    }
    .mvs-Content-wramp {
      .mvs-Content-list {
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        padding-top: 8px;
      }
      .mvs-Content-item {
        width: 25%;
        min-width: 240px;
        padding: 0px 43px 18px 0px;
        flex-shrink: 1;
      }
      .mvs-Content-box {
        position: relative;
        min-width: 160px;
        left: 5px;

        border-radius: 6px;
        overflow: hidden;
        &:hover {
          .mvs-Content-hover-background {
            opacity: 0.7;
          }
        }
      }

      .mvs-Content-img {
        height: 100%;
        width: 100%;
        border-radius: 6px;

        min-width: 270px;
      }
      .mvs-Content-top-img-title {
        position: absolute;
        top: 3px;
        right: 3px;
        color: #fff;
      }
      .mvs-Content-hover-background {
        position: absolute;
        margin: auto;
        left: 0;
        top: 0;
        right: 0;
        bottom: 40px;

        width: 50px;
        height: 50px;
        background-color: rgba(255, 255, 255, 0.7);
        line-height: 50px;
        text-align: center;
        color: red;
        border-radius: 50%;

        opacity: 0;
        transition: all 0.3s;

        .icon-play {
          font-size: 22px;
          margin-left: 1px;
        }
      }

      .mvs-Content-foot-songs {
        padding-top: 6px;
        font-size: 13px;
        color: #666;
        width: 100%;

        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }
      .mvs-Content-foot-sigers {
        margin-top: 10px;
        font-size: 12px;
        color: #d9d9d9;
        width: 100%;

        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }
    }
  }
}
//140x80
</style>